package com.ruoyi.project.note.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.project.note.domain.Vo.NotebookVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.note.domain.Notebook;
import com.ruoyi.project.note.service.INotebookService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 笔记集Controller
 * 
 * @author ruoyi
 * @date 2024-03-10
 */
@RestController
@RequestMapping("/note/notebook")
public class NotebookController extends BaseController
{
    @Autowired
    private INotebookService notebookService;

    /**
     * 查询笔记集列表
     */
//    @PreAuthorize("@ss.hasPermi('note:notebook:list')")
    @GetMapping("/list")
    public TableDataInfo list(Notebook notebook)
    {
        startPage();
        List<Notebook> list = notebookService.selectNotebookList(notebook);
        return getDataTable(list);
    }

    /**
     * 查询笔记集列表及二级表
     * @param notebook
     * @return
     */
    @GetMapping("/listVo")
    public TableDataInfo list(NotebookVo notebook)
    {
        startPage();
        List<NotebookVo> list = notebookService.selectNotebookVoList(notebook);
        return getDataTable(list);
    }

    /**
     * 导出笔记集列表
     */
//    @PreAuthorize("@ss.hasPermi('note:notebook:export')")
    @Log(title = "笔记集", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Notebook notebook)
    {
        List<Notebook> list = notebookService.selectNotebookList(notebook);
        ExcelUtil<Notebook> util = new ExcelUtil<Notebook>(Notebook.class);
        util.exportExcel(response, list, "笔记集数据");
    }

    /**
     * 获取笔记集详细信息
     */
//    @PreAuthorize("@ss.hasPermi('note:notebook:query')")
    @GetMapping(value = "/{notebookId}")
    public AjaxResult getInfo(@PathVariable("notebookId") Long notebookId)
    {
        return success(notebookService.selectNotebookByNotebookId(notebookId));
    }

    /**
     * 新增笔记集
     */
//    @PreAuthorize("@ss.hasPermi('note:notebook:add')")
    @Log(title = "笔记集", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Notebook notebook)
    {
        return toAjax(notebookService.insertNotebook(notebook));
    }

    /**
     * 修改笔记集
     */
//    @PreAuthorize("@ss.hasPermi('note:notebook:edit')")
    @Log(title = "笔记集", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Notebook notebook)
    {
        return toAjax(notebookService.updateNotebook(notebook));
    }

    /**
     * 删除笔记集
     */
//    @PreAuthorize("@ss.hasPermi('note:notebook:remove')")
    @Log(title = "笔记集", businessType = BusinessType.DELETE)
	@DeleteMapping("/{notebookIds}")
    public AjaxResult remove(@PathVariable Long[] notebookIds)
    {
        return toAjax(notebookService.deleteNotebookByNotebookIds(notebookIds));
    }
}
